<script>
/*
 * 图表配置基类，封装配置从store获取和提交操作以及其他一些通用操作，
 * 所有配置项从此类混合
 */
import { mapGetters } from 'vuex';
import * as types from '../../../store/types';

export default {
  name: 'BaseConfig',
  computed: {
    ...mapGetters(['controls', 'currentId']),
    chartOptions() {
      return this.controls[this.currentId].options;
    },
  },
  methods: {
    //提交配置到store
    updateOptions() {
      let currentControl = this.controls[this.currentId];
      currentControl.options = this.chartOptions;
      this.$store.commit(types.UPDATE_CHART_CONFIG, {
        data: { [this.currentId]: currentControl },
      });
    },
    //同步Series配置并提交配置到store
    updateSeriesAndOptions(key) {
      var series = this.chartOptions.extend.series;
      for (let i = 1; i < series.length; i++) {
        series[i][key] = series[0][key];
      }
      this.updateOptions();
    },
  },
};
</script>

<template>
  <div></div>
</template>
